float2 halfPixel;

texture blurredTex;
sampler blurredSampler = sampler_state 
{
	texture = <blurredTex>; 
	magfilter = LINEAR;
	minfilter = LINEAR;	
	AddressU = clamp;
	AddressV = clamp;
};

texture normalTex;
sampler normalSampler = sampler_state 
{
	texture = <normalTex>;
	magfilter = LINEAR;
	minfilter = LINEAR;
	AddressU = clamp;
	AddressV = clamp;
};

struct VS_INPUT
{
	float4 Position		: POSITION;
	float2 TexCoords	: TEXCOORD0;
};

struct VS_OUTPUT
{
	float4 Position		: POSITION;
	float2 TexCoords	: TEXCOORD0;
};

VS_OUTPUT Glow_VS (VS_INPUT Input)
{
	VS_OUTPUT Output;

	Output.Position  = Input.Position;
	Output.TexCoords = Input.TexCoords;
	
	return Output;
}

float4 Glow_PS (VS_OUTPUT Input) : COLOR0
{
	float4 colorBlur = tex2D(blurredSampler, Input.TexCoords + halfPixel.x);
	float4 colorNormal = tex2D(normalSampler, Input.TexCoords + halfPixel.y);
	
	colorBlur.r = saturate(colorBlur.r - 0.3) * 1.5;
	colorBlur.g = saturate(colorBlur.g - 0.3) * 1.5;
	colorBlur.b = saturate(colorBlur.b - 0.3) * 1.5;
	
	float4 darken = tex2D(blurredSampler, Input.TexCoords);
	
	darken.r = saturate(darken.r + 0.3);
	if (darken.r == 1) { darken.r = 0; }
	darken.g = saturate(darken.g + 0.3);
	if (darken.g == 1) { darken.g = 0; }
	darken.b = saturate(darken.b + 0.3);
	if (darken.b == 1) { darken.b = 0; }
	darken /= 10.0;
	
	return colorNormal * 1.5 + colorBlur - darken;
}

technique Glow
{
	pass P0
	{
		VertexShader = compile vs_2_0 Glow_VS();
		PixelShader = compile ps_2_0 Glow_PS();
	}
}
